package com.fufu.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RedisCache<T> {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 保存集合数据
     */
    public void saveList(String key, List<T> list) {
        redisTemplate.opsForList().leftPushAll(key, list);
    }
    /**
     * 查询数据
     */
    public List<T> getList(String key) {
        List<T> list = redisTemplate.opsForList().range(key, 0, -1);
        return list;
    }
    /**
     * 删除缓存中的数据
     */
    public void deleteList(String key) {
        redisTemplate.delete(key);
    }
}
